<?php

include_once($ROOT . "base.inc.php");

class PageController extends BaseController {
  var $contact;
  var $address;
  var $contacts;
  var $addresses;

  function PageController() {
  	parent::__construct();
	$this->title = "Contacts";
	$this->section = "contacts";

	$action = $this->getParameter("action");

	switch (strtoupper($action))
	{
		case "SEARCH" :
			$this->contact = new Contact();
			$this->address = new Address();
			$this->parseForm();

			$this->contacts = ContactLogic::findByExample($this->contact, $this->address);
			break;
		default :
		  $this->contacts = ContactLogic::findAll();
	}

	$this->addresses = AddressLogic::findAll();
  }

  function parseForm() {
	$this->contact->readForm();
	$this->address->readForm();
	if ($this->getParameter("zip") === null)
	{
		$this->address = null;
	}
	else
	{
		$this->address->id = $this->getParameter("address_id");
	}
  }

  function validate() {
	return (sizeof($this->errs) == 0);
  }

}



?>
